worker_processes auto;

events {}

http {
    upstream flask {
        server flask_app1:5000;
        server flask_app2:5000;
    }

    server {
        listen 80;
        server_name _;

        return 301 https://$host$request_uri;
    }

    server {
        listen 443 ssl;
        server_name flask;

        ssl_certificate /etc/nginx/certs/server.crt;
        ssl_certificate_key /etc/nginx/certs/server.key;

        location / {
            proxy_pass http://flask;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}

